#include<cstdio>
#include<cstring>
const int MAX = 2100000000;
char a[100];
int f[100][100],p[100][100];
int min(int x,int y)
{
	return x<y?x:y;
}
int main()
{
	freopen("test.in","r",stdin);
	scanf("%s",a);
	int n=strlen(a);
	//memset(f,0,sizeof(0));
	for(int i=0;i<n;i++)
		f[i][i]=1;
	for(int i=n-2;i>=0;i--)
		for(int j=i+1;j<n;j++)
		{
			f[i][j]=MAX;
			if(a[i]=='('&&a[j]==')'||a[i]=='['&&a[j]==']')f[i][j]=min(f[i][j],f[i+1][j-1]);
			if(a[i]=='('||a[i]=='[')f[i][j]=min(f[i][j],f[i+1][j]+1);
			if(a[j]==')'&&a[j]==']')f[i][j]=min(f[i][j],f[i][j-1]+1);
			for(int k=i;k<=j-1;k++)
				f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
		}
	printf("%d\n",f[0][n-1]);
	return 0;
}
			


